<template>
  <view>
    <template v-if="detail[8] || detail[9] || detail[10]">
      <template v-if="detail[8]">
        <view v-for="(item, index) in detail[8]" :key="`detail-8-${index}`" class="special-work-list__group">
          <view class="special-work-list__item" :class="{ 'flex-col': item.signatureUrl }">
            <text class="special-work-list__label">作业人签字：</text>
            <image
              v-if="item.reviewerSignatureUrl"
              :src="`${staticUrl}${item.reviewerSignatureUrl}`"
              mode="aspectFill"
              class="special-work__img"
              @click="handlePreviewImage([`${staticUrl}${item.reviewerSignatureUrl}`], 0)"
            ></image>
            <text v-else>{{ item.reviewerName }}</text>
          </view>
          <view class="special-work-list__item">
            <text class="special-work-list__label">签字时间：</text>
            <text class="special-work-list__value"
              ><uni-dateformat :date="item.createTime" format="yyyy-MM-dd hh:mm"></uni-dateformat
            ></text>
          </view>
        </view>
      </template>
      <view v-for="(item, index) in completion" :key="`detail-9-${index}`" class="special-work-list__group">
        <view class="special-work-list__item">
          <text class="special-work-list__label">作业完成时间：</text>
          <text class="special-work-list__value"
            ><uni-dateformat :date="item.createTime" format="yyyy-MM-dd hh:mm"></uni-dateformat
          ></text>
        </view>
        <view class="special-work-list__item">
          <text class="special-work-list__label">计划验收时间：</text>
          <text class="special-work-list__value">
            <uni-dateformat
              v-if="item.ticketReviewContent.acceptOfPlanStartTime"
              :date="item.ticketReviewContent.acceptOfPlanStartTime"
              format="yyyy-MM-dd hh:mm"
            ></uni-dateformat>
            <text>~</text>
            <uni-dateformat
              v-if="item.ticketReviewContent.acceptOfPlanEndTime"
              :date="item.ticketReviewContent.acceptOfPlanEndTime"
              format="yyyy-MM-dd hh:mm"
            ></uni-dateformat>
          </text>
        </view>
        <view class="special-work-list__item flex-col">
          <text class="special-work-list__label">完工照片：</text>
          <view class="flex">
            <image
              v-for="(image, index) in item.images"
              :key="index"
              :src="image"
              mode="aspectFill"
              class="special-work__img"
              @click="handlePreviewImage(item.images, index)"
            ></image>
          </view>
        </view>
        <view class="special-work-list__item" :class="{ 'flex-col': item.reviewerSignatureUrl }">
          <text class="special-work-list__label">提验签字：</text>
          <view>
            <image
              v-if="item.reviewerSignatureUrl"
              :src="`${staticUrl}${item.reviewerSignatureUrl}`"
              mode="aspectFill"
              class="special-work__img"
              @click="handlePreviewImage([`${staticUrl}${item.reviewerSignatureUrl}`], 0)"
            ></image>
            <text v-else>{{ item.reviewerName }}</text>
          </view>
        </view>
      </view>

      <view v-for="(item, index) in acceptance" :key="`detail-10-${index}`" class="special-work-list__group">
        <view class="special-work-list__item">
          <text class="special-work-list__label">实际验收时间：</text>
          <text class="special-work-list__value">
            <uni-dateformat
              v-if="item.ticketReviewContent.acceptStartTime"
              :date="item.ticketReviewContent.acceptStartTime"
              format="yyyy-MM-dd hh:mm"
            ></uni-dateformat>
            <text>~</text>
            <uni-dateformat
              v-if="item.ticketReviewContent.acceptEndTime"
              :date="item.ticketReviewContent.acceptEndTime"
              format="yyyy-MM-dd hh:mm"
            ></uni-dateformat>
          </text>
        </view>
        <view class="special-work-list__item">
          <text class="special-work-list__label">验收意见：</text>
          <text class="special-work-list__value">{{ item.reviewResultLabel }}</text>
        </view>
        <view class="special-work-list__item">
          <text class="special-work-list__label">审查意见说明：</text>
          <text class="special-work-list__value">{{ item.reviewDescription }}</text>
        </view>
        <view class="special-work-list__item" :class="{ 'flex-col': item.reviewerSignatureUrl }">
          <text class="special-work-list__label">验收签字：</text>
          <image
            v-if="item.reviewerSignatureUrl"
            :src="`${staticUrl}${item.reviewerSignatureUrl}`"
            mode="aspectFill"
            class="special-work__img"
            @click="handlePreviewImage([`${staticUrl}${item.reviewerSignatureUrl}`], 0)"
          ></image>
          <text v-else>{{ item.reviewerName }}</text>
        </view>
        <view class="special-work-list__item">
          <text class="special-work-list__label">签字时间：</text>
          <text class="special-work-list__value">
            <uni-dateformat :date="item.createTime" format="yyyy-MM-dd hh:mm"></uni-dateformat>
          </text>
        </view>

        <view class="special-work-list__item flex-col">
          <text class="special-work-list__label">验收照片</text>

          <view class="flex">
            <image
              v-for="(image, index) in item.images"
              :key="index"
              :src="image"
              mode="aspectFill"
              class="special-work__img"
              @click="handlePreviewImage(item.images, index)"
            ></image>
          </view>
        </view>
      </view>
    </template>
    <empty v-else></empty>
  </view>
</template>

<script>
import { staticUrl } from '@/config.js'
import Empty from '@/components/cu-empty/index.vue'
export default {
  props: {
    detail: {
      type: Object,
      default: () => ({})
    }
  },
  components: {
    Empty
  },
  computed: {
    completion() {
      if (!this.detail[9]) {
        return []
      }
      return this.detail[9].map((item) => {
        item.images = item.ticketReviewContent.images.split(',').map((image) => {
          return `${staticUrl}${image}`
        })
        return item
      })
    },
    acceptance() {
      if (!this.detail[10]) {
        return []
      }
      return this.detail[10].map((item) => {
        item.images = item.ticketReviewContent.images.split(',').map((image) => {
          return `${staticUrl}${image}`
        })
        return item
      })
    }
  },
  data() {
    return {
      staticUrl
    }
  },
  methods: {
    handlePreviewImage(urls, current) {
      uni.previewImage({
        current,
        urls
      })
    }
  }
}
</script>

<style scoped lang="scss">
@import '../style/style.scss';
</style>
